package cn.wmw.xyy.mq;

import cn.wmw.xyy.domain.MediaFile;
import cn.wmw.xyy.service.IMediaFileService;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup = "media-push-consumer",
        topic = "media-topic",
        selectorExpression = "push-tag",
        messageModel = MessageModel.CLUSTERING
)
public class MediaVideoConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private IMediaFileService iMediaFileService;

    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        String str = new String(body, StandardCharsets.UTF_8);
        MediaFile mediaFile = JSON.parseObject(str, MediaFile.class);
        iMediaFileService.handleFile2m3u8(mediaFile);
    }
}
